package org.hk.kg.web.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.hk.kg.utils.LocalResouce;
import org.hk.kg.web.BaseAction;
import org.hk.kg.web.HtmlRender;

public class ImageRender implements HtmlRender{
	private static final Pattern IMAGE_PATTNER = Pattern.compile(".*\\<img .*\\>.*",Pattern.CASE_INSENSITIVE);
	private static final Pattern SRC_PATTERN = Pattern.compile("src\\=\"([^\"]*)\"");
	public boolean validate(String line) {
		Matcher m = IMAGE_PATTNER.matcher(line);
		return m.matches();
	}

	public String execute(String line, BaseAction context) {
		Matcher m = SRC_PATTERN.matcher(line);
		while(m.find())
		{
			line = m.replaceAll("src=\""+ LocalResouce.getImageFile(m.group(1)) +"\"");
		}
		return line;
	}
}
